1. Field of the Invention
The present invention generally relates to a data protection method, in particular, to a data protection method for power failure and a controller using the same.
2. Description of Related Art
Along with the widespread of digital cameras, camera phones, and MP3 in recently years, the consumers' demand to storage media has increased drastically too. Flash memory is one of the most adaptable memories for such battery-powered portable products due to its characteristics such as data non-volatility, low power consumption, small volume, and non-mechanical structure. Besides being applied in foregoing portable products, flash memory is also broadly applied to external products such as flash cards and flash drives. Thereby, flash memory has become one of the most focused electronic products in recent years.
A flash memory is usually managed in unit of blocks. The problem of incorrect or instable data may be caused if one logical block is mapped to a plurality of physical blocks in a flash memory and a power failure occurs while writing data into the flash memory. In other words, the system cannot identify physical blocks containing original data and physical blocks containing new data after the power supply is resumed.
Conventionally, to resolve foregoing problem, related information is recorded in a byte of a redundant area in each page of a physical block. Taking a flash memory in which three physical blocks are mapped to one logical block as example, different indicators are respectively written into a selected byte based on the fact that each bit in a flash memory can be changed from 1 to 0. For example, FF is written for indicating that the data is recorded during a first period, 0F is written to replace FF for indicating that the data is recorded during a second period, and 00 is written to replace 0F for indicating that the data is recorded during a third period. In other words, the data recorded is the newest data if the indicator is FF, the data recorded is older data if the indicator is 0F, and the data recorded is the oldest data if the indicator is 00.
However, the conventional technique described above has following problem. If the memory used is a multi-level cell (MLC) NAND flash memory, foregoing method of writing indicators into the memory in multiple times cannot be adopted because this kind of flash memory can be written only once. In other words, the indicator cannot be changed once it is written into a MLC NAND flash memory.
Thereby, it is needed to provide a data protection method for identifying the update relationship of blocks in a memory after a power failure.